import {appRouter} from '@/router/router'
import {getStore} from '@/lib/store'
import {showThisRoute} from '@/lib/util'
export default {
    //页面获取用户信息
    getUserInfo: state => state.userInfo, //获取用户信息
    getMenuActive: state => state.menuActive, 
    getMenuOpened: state => state.menuOpened,
    //处理权限过滤
    getMenuList : state => {
        let menuList = [];
        let accessCode = state.rules;
        console.log("accessCode",accessCode);
		menuList = [];
        appRouter.forEach(item=>{
            //判断是否有权限字段
            if (item.access !== undefined) {        
                //判断是否有权限
                if (accessCode.indexOf(item.access) >= 0 ) {
                    //判断是否有二级菜单
                    if (item.children === undefined ) {
                        menuList.push(item);
                    } else {
                        let len = menuList.push(item);
                        let childrenArr = [];
                        //返回有权限的数据菜单
                        childrenArr = item.children.filter(child => {
                            if (child.access !== undefined) {
                                //判断二级菜单是否有权限
                                if (accessCode.indexOf(child.access)>= 0) {
                                    return child;
                                }
                            } else {
                                return child;
                            }
                        });
                        menuList[len - 1].children = childrenArr;
                    }
                }
            }else{
                if (item.children === undefined ) {
                        menuList.push(item);
                    } else {
                        let len = menuList.push(item);
                        let childrenArr = [];
                        childrenArr = item.children.filter(child => {
                            if (child.access !== undefined) {
                                if (accessCode.indexOf(child.access)>= 0) {
                                    return child;
                                }
                            } else {
                                return child;
                            }
                        });
                        let handledItem = menuList[len - 1];
                        handledItem.children = childrenArr;
                        menuList.splice(len - 1, 1, handledItem);
                    }

            }
        })
        
        return menuList
    }

    
}
